package view;

import javax.swing.JSplitPane;
import controller.BrowsePanelMouseListener;

public class MainPanel extends JSplitPane {

	
	private static final long serialVersionUID = 1L;
	public MainPanel(MainFrame f) {		
		
		frame = f;
		setOrientation(JSplitPane.HORIZONTAL_SPLIT);		
		setResizeWeight(0.5);
		
		left_panel  = new BrowsePanel(frame, "l");
		right_panel = new BrowsePanel(frame, "p");	
		
		setPrimaryPanel(left_panel);
		
		left_panel.addMouseListener(new BrowsePanelMouseListener(this)); 
		right_panel.addMouseListener(new BrowsePanelMouseListener(this)); 
		
		this.setLeftComponent(left_panel);
		this.setRightComponent(right_panel);
		
	}	
	
	public void setPrimaryPanel(BrowsePanel panel) {
		primary = panel;
		getSecondary().setNonActive();
		getPrimary().setActive();
	}		
	
	public void setSecondaryPanel(BrowsePanel panel) {
		getSecondary().setActive();
		getPrimary().setNonActive();
		primary = panel;
	}
	
	public void updateNames(){
		left_panel.updateNames();
		right_panel.updateNames();
	}
	
	public BrowsePanel getPrimary() {		
		return primary;		
	}
	
	public BrowsePanel getSecondary() {		
		if (primary.equals(left_panel)) {
			return right_panel;
		} else {
			return left_panel;
		}		
	}
	
	public void changeBrowsePanel(String name) {
		if (primary.getName() != name)		
			setSecondaryPanel(getSecondary());
	
	}		
	
	
	public BrowsePanel getLeft_panel() {
		return left_panel;
	}

	public void setLeft_panel(BrowsePanel left_panel) {
		this.left_panel = left_panel;
	}

	public BrowsePanel getRight_panel() {
		return right_panel;
	}

	public void setRight_panel(BrowsePanel right_panel) {
		this.right_panel = right_panel;
	}
	
	private MainFrame frame;
	private BrowsePanel left_panel;
	private BrowsePanel right_panel;
	private BrowsePanel primary;
	
	
}
